home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1939 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Performance: C vs. C++
  5. Date: 14 Jan 1996 10:43:18 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4damo6$338@news1.usa.pipeline.com>
  8. References: <4da9pn$a45@news.bridge.net>
  9. NNTP-Posting-Host: pipe8.h1.usa.pipeline.com
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete)
  13. X-Newsreader: Pipeline USA v3.3.0
  14.  
  15. On Jan 14, 1996 07:02:15 in article <Re: Performance: C vs. C++>, 'David
  16. Byrden <100101.2547@compuserve.com>' wrote: 
  17.  
  18.  
  19. >Steve; 
  20. >C and C++ are so similar that I would expect similar code to produce  
  21. >almost identical performance. However, note that while virtual functions  
  22. >cause overhead when you use them, exceptions in most present compilers can
  23.  
  24. >cause overhead *at every function call*. 
  25. Looking at .asm output of source code compiled with MSVC++4.0 revealed 
  26. that the cost of exception is only in the routines actually containing 
  27. exception code.   The following points consider the cost only if an 
  28. exception is not thrown.  I don't think we really care how much extra 
  29. is involved when an exception acctually occurs. 
  30.  
  31. I you have try - catch blocks in your code and call a function 
  32. from within as well as outside the try block, there's an extra push 
  33. instruction in invoking the call and an extra add-esp upon return 
  34. involved in the call inside the try.   
  35.  
  36. The 'setup' for the try block itself is appears to be not much.  I need 
  37. to do some more experimenting to find out just how many extra 
  38. instructions are involved.  Right now I'll say it's peanuts.  Inside 
  39. the try block is an extra push and one extra jump (to bypass the 
  40. catch blocks).  There appears to be some exception related 
  41. instructions in a section some distance from the try-catch blocks. 
  42.  
  43. If you have a throw in a function, then there are six extra instructions 
  44. upon entry to the function, but none on exit.  The extras are three 
  45. push, two mov and one sub.  (Not counting the code to test 
  46. whether or not an exception should be thrown.) 
  47.  
  48. So, the bottom line:  The cost is definitely there where the exception 
  49. code exists, but in code that is not involved, there's none.  Don't 
  50. forget that this investigation was performed only on one compiler  
  51. in one environment (Win95) and may produce similar results 
  52. elsewhere. 
  53.  
  54. -- 
  55. Pete Grant 
  56. Kalevi, Inc. 
  57. Object Oriented Software Development
  58.